package com.minglead.springboot.common.config.webxmladapter;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

import javax.annotation.Priority;
import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
/*import org.apache.shiro.cache.ehcache.EhCacheManager;*/
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.servlet.SimpleCookie;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.annotation.Order;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import com.alibaba.druid.util.StringUtils;
import com.minglead.springboot.common.config.Global;
import com.minglead.springboot.common.config.webxmladapter.servlet.ValidateCodeServlet;
import com.minglead.springboot.common.security.shiro.session.CacheSessionDAO;
import com.minglead.springboot.common.security.shiro.session.SessionDAO;
import com.minglead.springboot.common.security.shiro.session.SessionManager;
import com.minglead.springboot.common.utils.IdGen;
import com.minglead.springboot.common.utils.SpringContextHolder;
import com.minglead.springboot.platform.sys.listener.WebContextListener;
import com.minglead.springboot.platform.sys.security.CustomCredentialsMatcher;
import com.minglead.springboot.platform.sys.security.SystemAuthorizingRealm;


/**
 * Servlet 配置
 * @author clz
 * @date 2018年5月17日
 */
@Configuration
@ConditionalOnProperty(name="druid.stat.enabled", havingValue="true", matchIfMissing=true)
public class DruidStatConfiguration {
	/**
	 * 注册DruidFilter拦截
	 */
	@Bean
	public FilterRegistrationBean duridFilter() {
		FilterRegistrationBean bean = new FilterRegistrationBean();
		bean.setFilter(new WebStatFilter());
		bean.addInitParameter("exclusions", "*.css,*.js,*.png,"
				+ "*.jpg,*.gif,*.jpeg,*.bmp,*.ico,*.swf,*.psd,*.htc,*.htm,*.html,"
				+ "*.crx,*.xpi,*.exe,*.ipa,*.apk,*.otf,*.eot,*.svg,*.ttf,*.woff,"
				+ "/druid/*");
		bean.addUrlPatterns("/*");
		return bean;
	}
	
	/**
	 * 注册DruidServlet
	 */
	@Bean
	public ServletRegistrationBean druidServlet() {
		ServletRegistrationBean bean = new ServletRegistrationBean();
		bean.setServlet(new StatViewServlet());
		bean.addUrlMappings("/druid/*");
		return bean;
	}
}